/*
 * REFXMLReader.cpp
 *
 *  Created on: Mar 13, 2013
 *      Author: Lucifer
 */

#include "../pch.h"
#include "core/REFXMLTextReaderImpl.h"

namespace BFX
{

//////////////////////////////////////////////////////////////////////////////
// Gets the name of the current node, including the namespace prefix.
UniString REFXMLReader::GetName() const
{
	if (GetPrefix().IsEmpty())
		return GetLocalName();
	else
		return GetNameTable()->Add(GetPrefix() + (UCHAR)':' + GetLocalName());
}

// Gets a value indicating whether the current node is an attribute that was generated from the default value defined in the DTD or schema.
bool REFXMLReader::IsDefault() const
{
	return false;
}


//////////////////////////////////////////////////////////////////////////////

// Initializes a new instance of the REFXMLTextReader class with the specified text reader.
REFXMLTextReader::REFXMLTextReader(REFUniTextReader* pInput)
{
	m_pImplementation = new REFXMLTextReaderImpl(pInput, new REFHashNameTable());
	m_pImplementation->AddRef();
}

REFXMLTextReader::REFXMLTextReader(REFUniTextReader* pInput, REFNameTable* pNameTable)
{
	m_pImplementation = new REFXMLTextReaderImpl(pInput, pNameTable);
	m_pImplementation->AddRef();
}

REFXMLTextReader::~REFXMLTextReader()
{
	m_pImplementation->Release();
}


// Get the type of the current node.
XMLNodeType REFXMLTextReader::GetNodeType() const
{
	return m_pImplementation->GetNodeType();
}

// Gets the name of the current node, including the namespace prefix.
UniString REFXMLTextReader::GetName() const
{
	return m_pImplementation->GetName();
}

// Gets the name of the current node without the namespace prefix.
UniString REFXMLTextReader::GetLocalName() const
{
	return m_pImplementation->GetLocalName();
}

// Gets the namespace URN (as defined in the W3C Namespace Specification) of the current namespace scope.
UniString REFXMLTextReader::GetNamespaceURI() const
{
	return m_pImplementation->GetNamespaceURI();
}

// Gets the namespace prefix associated with the current node.
UniString REFXMLTextReader::GetPrefix() const
{
	return m_pImplementation->GetPrefix();
}

// Gets a value indicating whether
bool REFXMLTextReader::HasValue() const
{
	return m_pImplementation->HasValue();
}

// Gets the text value of the current node.
UniString REFXMLTextReader::GetValue() const
{
	return m_pImplementation->GetValue();
}

// Gets the base URI of the current node.
UniString REFXMLTextReader::GetBaseURI() const
{
	return m_pImplementation->GetBaseURI();
}

// Gets a value indicating whether the current node is an empty element (for example, <MyElement/>).
bool REFXMLTextReader::IsEmptyElement() const
{
	return m_pImplementation->IsEmptyElement();
}

// Gets a value indicating whether the current node is an attribute that was generated from the default value defined in the DTD or schema.
bool REFXMLTextReader::IsDefault() const
{
	return m_pImplementation->IsDefault();
}

// Gets the xml name-table associated with the xml reader.
REFNameTable* REFXMLTextReader::GetNameTable() const
{
	return m_pImplementation->GetNameTable();
}

// Moving through the stream, reads next node from the input data.
// Returns true if the next node was read successfully; false if there are no more nodes to read.
bool REFXMLTextReader::Read()
{
	return m_pImplementation->Read();
}

// Closes the stream, changes the ReadState to Closed, and sets all the properties back to empty
// string.
void REFXMLTextReader::Close()
{
	m_pImplementation->Close();
}

// Returns the read state of the XmlReader.
ReadState REFXMLTextReader::GetReadState() const
{
	return m_pImplementation->GetReadState();
}

// Spefifies whether general entities should be automatically expanded or not
XMLEntityHandling REFXMLTextReader::GetEntityHandling() const
{
	return m_pImplementation->GetEntityHandling();
}

void REFXMLTextReader::SetEntityHandling(XMLEntityHandling entityHandling)
{
	m_pImplementation->SetEntityHandling(entityHandling);
}

const XMLErrorContext& REFXMLTextReader::GetLastError() const
{
	return m_pImplementation->GetLastError();
}
bool REFXMLTextReader::IsErrorOccurred() const
{
	return m_pImplementation->IsErrorOccurred();
}

REFXMLSchemaInfo* REFXMLTextReader::GetDtdSchemaInfo() const
{
	return m_pImplementation->GetDtdSchemaInfo();
}

// Disables or enables support of W3C XML 1.0 Namespaces
void REFXMLTextReader::SetSupportNamespaces(bool bSupportNamespaces)
{
	return m_pImplementation->SetSupportNamespaces(bSupportNamespaces);
}

bool REFXMLTextReader::IsSupportNamespaces() const
{
	return m_pImplementation->IsSupportNamespaces();
}

bool REFXMLTextReader::IsNormalization() const
{
	return m_pImplementation->IsNormalization();
}
void REFXMLTextReader::SetNormalization(bool bNormalization)
{
	m_pImplementation->SetNormalization(bNormalization);
}

UniString REFXMLTextReader::GetEncoding() const
{
	return m_pImplementation->GetEncoding();
}

// If on attribute, moves to the element that contains the attribute node
bool REFXMLTextReader::MoveToElement()
{
	return m_pImplementation->MoveToElement();
}

// Moves to the first attribute of the current node
bool REFXMLTextReader::MoveToFirstAttribute()
{
	return m_pImplementation->MoveToFirstAttribute();
}

// Moves to the next attribute of the current node
bool REFXMLTextReader::MoveToNextAttribute()
{
	return m_pImplementation->MoveToNextAttribute();
}

// Moves to an attribute at the specified index (position)
void REFXMLTextReader::MoveToAttribute(int i)
{
	m_pImplementation->MoveToAttribute(i);
}

// Moves to an attribute with the specified Name
bool REFXMLTextReader::MoveToAttribute(const UniString& strName)
{
	return m_pImplementation->MoveToAttribute(strName);
}

// Moves to an attribute with the specified LocalName and NamespceURI
bool REFXMLTextReader::MoveToAttribute(const UniString& strLocalName, const UniString& strNamespaceURI)
{
	return m_pImplementation->MoveToAttribute(strLocalName, strNamespaceURI);
}

// Parses the attribute value into one or more Text and/or EntityReference node types.
bool REFXMLTextReader::ReadAttributeValue()
{
	return m_pImplementation->ReadAttributeValue();
}

}	//	namespace BFX
